﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Homework12.Models
{
    public class OrderItem
    {
        public Goods OrderGoods { get; set; }
        public int Quantity { get; set; }
        public double Price { get; set; }

        public OrderItem(Goods goods, int quantity)
        {
            this.OrderGoods = goods;
            this.Quantity = quantity;
            this.Price = this.OrderGoods.UnitPrice * quantity;
        }

        public OrderItem() { }
        public override string ToString()
        {
            return OrderGoods.ToString() + " " + Quantity + "kg ItemPrice:" + Price + "yuan\n";
        }

        public override bool Equals(object obj)
        {
            var item = obj as OrderItem;
            return item != null &&
                   EqualityComparer<Goods>.Default.Equals(OrderGoods, item.OrderGoods) &&
                   Quantity == item.Quantity &&
                   Price == item.Price;
        }

        public override int GetHashCode()
        {
            var hashCode = -1732923583;
            hashCode = hashCode * -1521134295 + EqualityComparer<Goods>.Default.GetHashCode(OrderGoods);
            hashCode = hashCode * -1521134295 + Quantity.GetHashCode();
            hashCode = hashCode * -1521134295 + Price.GetHashCode();
            return hashCode;
        }
    }
}